package com.heima.test05;

import java.util.Scanner;

public class PhoneTest {
    public static void main(String[] args) {
        //定义一个对象数组存储3部手机，并计算平均价格
        Phone[] arr = new Phone[3];

        //老样子取值
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            Phone p = new Phone();
            System.out.println("请输入第" + (i + 1) + "个手机的品牌");
            String brand = sc.next();
            p.setBrand(brand);
            System.out.println("请输入第" + (i + 1) + "个手机的价格");
            double price = sc.nextDouble();
            p.setPrice(price);
            System.out.println("请输入第" + (i + 1) + "个手机的颜色");
            String color = sc.next();
            p.setColor(color);

            arr[i] = p;
        }
        //定义均值
        int avg = 0;
        for (int i = 0; i < arr.length; i++) {
            Phone phone = arr[i];
            System.out.println("品牌:" + phone.getBrand() + " 价格：" + phone.getPrice() + " 颜色：" + phone.getColor());
            avg += phone.getPrice();
        }
        System.out.println("平均价格为：" + avg / arr.length);
    }
}
